import { defineStore } from 'pinia'

export interface IFavorite {
    menuId: string;
    title: string;
    fullPath: string;
}

export const useFavoriteStore = defineStore('favoriteStore', {
    state: () => {
        return {
            fav: [] as Array<IFavorite>
        }
    },
    getters: {
        getFavorite(state): Array<IFavorite> {
            return state.fav
        }
    },
    actions: {
        /**
         * 收藏菜单
         * @param data 收藏的菜单
         */
        setFavorite(data: IFavorite) {
            this.fav.push(data)
        },
        /**
         * 取消收藏的菜单
         * @param id 菜单id
         */
        cancleFavorite(id: string) {
            const index = this.fav.findIndex((item) => item.menuId === id)
            this.fav.splice(index, 1)
        }
    }
})
